using Shinkansen.Core;
using Shinkansen.Runtime;

namespace Shinkansen.Model
{
    public class QueryStringWithCrunchingBuilder : IQueryStringBuilder
    {
        private readonly IQueryStringBuilder _builder;
        private readonly bool _crunch;

        /// <summary>
        /// Initializes a new instance of the <see cref="QueryStringWithCrunchingBuilder"/> class.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="crunch">if set to <c>true</c> crunch content (minify, etc).</param>
        public QueryStringWithCrunchingBuilder (IQueryStringBuilder builder, bool crunch)
        {
            _builder = builder;
            _crunch = crunch;
        }

        /// <summary>
        /// Builds the specified query string.
        /// </summary>
        /// <param name="queryString">The query string.</param>
        public void ConstructQueryString (QueryString queryString)
        {
            _builder.ConstructQueryString (queryString);

            if (_crunch)
                queryString[Tokens.Crunch] = _crunch.ToString ();
        }
    }
}